//----------------------------------------------------------------------------------
// CBlock class
// Author: Cristian Valls
//
// Description:
// Clase que posee el comportamiento de los bloques del Arkanoid
//----------------------------------------------------------------------------------
#include "__PCH_Arkanoid.h"
#include <iostream>
#include "Block.h"

using namespace std;

CBlock::CBlock (std::string sName, uint32 uIdBlock, uint32 uHitsLeft, Vect2f vPosition, BLOCK_STATE eBlockState)
{
	m_sBlock = NULL;
	m_uIdBlock = uIdBlock;
	m_uHitsLeft = uHitsLeft;
	m_vPosition = vPosition;
	m_eBlockState = eBlockState;
	m_uIdActiveSprite = 0;

	Init();
}

void CBlock::AddSpriteMap (std::pair<uint32, CSpriteEpic*> uMapSprite)
{
	m_mapSprites.insert(uMapSprite);
	if (m_sBlock == NULL){
		m_sBlock = GetActiveSprite(0);
	}
}


bool CBlock::Init()
{	
	m_bIsOk = true;

	return m_bIsOk;
}

void CBlock::Done()
{
	if (m_bIsOk){
		Release();
	}	
}

void CBlock::Release()
{
	m_mapSprites.clear();
}

CSpriteEpic* CBlock::GetActiveSprite (uint32 l_sIdSprite)
{
	mapSprites::iterator l_itTextures;

    for (l_itTextures = m_mapSprites.begin(); l_itTextures != m_mapSprites.end(); ++l_itTextures)
    {
        uint32 ID = l_itTextures->first;

        if (ID == l_sIdSprite)
        {
            return l_itTextures->second;
        }
	}

	return NULL;	
}

CSpriteEpic* CBlock::GetActiveSprite ()
{
	mapSprites::iterator l_itTextures;

    for (l_itTextures = m_mapSprites.begin(); l_itTextures != m_mapSprites.end(); ++l_itTextures)
    {
        uint32 ID = l_itTextures->first;

        if (ID == m_uIdActiveSprite)
        {
            return l_itTextures->second;
        }
	}

	return NULL;	
}

void CBlock::SetHitsLeft(const uint32 uHitsLeft)
{	
	//m_uIdActiveSprite++;
	m_sBlock = GetActiveSprite(m_uIdActiveSprite);
	m_uHitsLeft = uHitsLeft;
}

void CBlock::SetPosition(const Vect2f vPosition)
{
	m_vPosition = vPosition;
}

void CBlock::SetBlockState(const BLOCK_STATE eBlockState)
{
	m_eBlockState = eBlockState;
}